#include <stdio.h>
#include <time.h>
#include <math.h>
//方法一
long add_1(long n)
{  long i,sum=0;
   for(i=1;1<=n;i++)
      sum+=i;
    return sum;
}

void add_1_time(long n)
{
   clock_t t;
   long sum;
   t = clock();
   sum = add_1(n);
   t = clock() - t;
   printf("方法一：\n");
   printf("结果:1~%ld之和 :%ld\n",n,sum);
   printf("用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC);
   

}

//方法二
long add_2(long n )
{   long sum;
   sum = n*(n + 1)/2;
   return sum;
}

void add_2_time(long n)
{
   clock_t t;
   long sum;
   t = clock();
   sum = add_2(n);
   t = clock() - t;
   printf("方法二：\n");
   printf("结果:1~%ld之和 :%ld\n",n,sum);
   printf("用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC);
}


int main()
{  
   int n,sum;
   printf("n输入的值必须要大于(10000):"); 
   scanf("%d",&n);
   if (n<10000) 
      return 0;
   else
      add_1_time(n);
      add_2_time(n);
   return 1;
}